1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
import { getHonoContext } from "waku/unstable_hono";
import { Button } from "@/components/ui/button";
import { Link } from "waku";
import { getContext, getContextData } from "waku/middleware/context";
import * as WServer from "waku/server";
import type { PageProps } from "waku/router";
import db from "@/lib/db";
import { useCookies } from "@/lib/server/cookiebridge";
import Deck from "@/components/Flashcard/Deck";
import Deck2 from "@/components/Flashcard/Deck2";
import { CardFront, CardBack } from "@/components/Flashcard/ServerCard";
const flags: Record<string, string> = {
th: "🇹🇭",
en: "🇬🇧",
zh: "🇨🇳",
ja: "🇯🇵",
es: "🇪🇸",
fr: "🇫🇷",
};
export default async function HomePage(props: PageProps<"/lesson/[slug]">) {
const hctx: any = getHonoContext();
console.log({ hctx });
const ctx = getContext();
console.log(ctx.req.headers, "heders");
hctx.set("lol", "lmao");
const cokis = useCookies();
const coki = cokis.getCookie("sorlang");
console.log({ coki });
console.log({ props });
// const { user } = getContextData() as any;
// console.log({ user });
const user = { id: 2 };
const data = await getData(Number(props.slug), user.id);
if ("error" in data) return <p>Error</p>;
// console.log({ data });
const cardComponents = data.ok.cards.map((card) => ({
id: card.id,
front: <CardFront data={card} />,
back: <CardBack data={card} />,
}));
return (
<>
<section>
<h2 className="text-lg">Thai!</h2>
<Deck2 data={data.ok} cards={cardComponents} />
</section>
</>
);
}
const getData = async (lesson: number, userId: number) => {
const lessons = db.fetchLesson(userId, lesson);
return lessons;
};
export const getConfig = async () => {
return {
render: "dynamic",
} as const;
};
async function LanguageItem({ lang }: { lang: string }) {
return (
<div className="flex">
<div className="text-lg">{flags[lang] || ""}</div>
</div>
);
}
|